<?php
class mis_data_technical_model extends MY_Model {
	var $nama_tabel = 'ADMIN_PRIMKOKAS.MIS_PENGADUAN';
	function getApp()
	{
		$ls_sql	= "	SELECT	APP_ID value,
							APP_NAME display
					FROM	ADMIN_PRIMKOKAS.IT_APPLICATION
					ORDER BY APP_NAME";
					
		$result	= $this->db->query($ls_sql);
		if($result->num_rows() > 0){
			return $result->result_array();
		}else{
			return array();
		}
	}
	function GetJSON() {
		$ls_sql	= "	SELECT p.KODE_PENGADUAN,p.NAMA_PENGADU,a.APP_NAME,
					p.TANGGAL_PENGADUAN,p.URAIAN_PENGADUAN,p.SOLUSI,p.STATUS,p.TANGGAL_SELESAI
					FROM	".$this->nama_tabel." p
					LEFT JOIN ADMIN_PRIMKOKAS.IT_APPLICATION a ON a.APP_ID=p.APP_ID
					WHERE	UPPER(KODE_PENGADUAN) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(NAMA_PENGADU) LIKE '%".strtoupper(post('keyword'))."%'
							OR UPPER(APP_NAME) LIKE '%".strtoupper(post('keyword'))."%'
					ORDER BY ".(post('sort')=='' ? 'KODE_PENGADUAN' : post('sort'))." ".(post('order')=='' ? 'asc' : post('order'));
	
		return json_encode( $this->paging($ls_sql) );

	}

	function Add($arr_data){
		$this->db->insert($this->nama_tabel, $arr_data);
	}

	function Update($arr_data, $arr_rule){
		$this->db->update($this->nama_tabel, $arr_data, $arr_rule);
	}

	function DeleteSingle($arr_rule) {
		try {
			if(	intval($this->get_data("SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.MIS_PENGADUAN WHERE KODE_PENGADUAN = '".$arr_rule['kode_pengaduan']."'"))<1)
			{
				return $this->error_delete.' [id: '.$arr_rule['kode_pengaduan']."]<br /> SELECT COUNT(1) FROM ADMIN_PRIMKOKAS.MIS_PENGADUAN WHERE KODE_PENGADUAN = '".$arr_rule['kode_pengaduan']."'";
			}else{
				$this->db->delete('ADMIN_PRIMKOKAS.MIS_PENGADUAN', array('kode_pengaduan' => $arr_rule['kode_pengaduan']));
				return '';
			}
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}

}
?>